import Vue 			from 'vue'
import util 		from '../../util'
import axios 		from 'axios'
import { Toast,Dialog,List } 	from 'vant';
Vue.use(Toast,Dialog,List);

export default {
	name: 'myMore',
	data(){
		return {
			iconShown:false,		//选择弹窗
			iconList:[
				{ id:0,name: '红涨绿跌',color:'' },
				{ id:1,name: '绿涨红跌',color:'' },
			],
			defaultSet:{},

			iconShown2:false,		//选择弹窗
			iconList2:[
				{ id:1,name: '平台默认',color:'' },
				{ id:2,name: '跟随系统',color:'' },
			],
			defaultSet2:{},

			needUpdate:false,		//是否有更新
		}
	},
	methods:{
		loginOut(){
			Dialog.confirm({
                title: '提醒',
                message: '确定退出登录？',
                className:'sellType-dialog',
                cancelButtonColor:'#1989fa',
                confirmButtonText:'确定',
                cancelButtonText:'取消',
                overlayClass:'sellType-mark'
            }).then(() => {
            	//加退出清除，防止万一安卓无法清除
            	// window.localStorage.removeItem('token');
                // util.delCookie('localToken');
            	util.callHandler('settingLogout',{},res => {
            		// localStorage.removeItem('token');
                    // util.delCookie('localToken');
				})
                console.log('confirm')
            }).catch(() => {
                console.log('cancel')
            })
        },
		selectIcon(ele){
			this.defaultSet = {
				id:ele.id,
				name:ele.name
			}
			this.iconList.map(item => {
				item.color = item.id === ele.id?'#0080FF':'';
			})
			this.iconShown = !this.iconShown;
			//设置猜涨跌颜色
			util.callHandler('updateUpKLineColor',ele.id,res => {
				console.log(res)
			})
		},
		selectIcon2(ele){
			this.defaultSet2 = {
				id:ele.id,
				name:ele.name
			}
			this.iconList2.map(item => {
				item.color = item.id === ele.id?'#0080FF':'';
			})
			this.iconShown2 = !this.iconShown2;
			// util.callHandler('updateUpKLineColor',ele.id,res => {
			// 	console.log(res)
			// })
		},
		jump(num){
			if(num == 1){
				//跳转到我的设置页面
				this.$router.push({
					path:'/mySetting',
					query:{}
				})
			}else if(num == 2){
				//设置猜涨跌颜色
				this.iconShown = !this.iconShown;
			}else if(num == 3){
				//跳转到客服
				util.callHandler('openUrl',{
					url:'bbjApp://servicerinfo',
					title:'联系客服',
					needLogin:true,
					popVC:false,		//跳转的时候是否干掉当前页面
					hiddenNav:true,		//是否全屏
				},res => {
					console.log(res)
				})
			}else if(num == 4){
				//常见问题
				util.callHandler('openUrl',{
					url:'bbjApp://common_question',
					title:'常见问题',
					needLogin:true,
					popVC:false,		//跳转的时候是否干掉当前页面
					hiddenNav:true,		//是否全屏
				},res => {
					console.log(res)
				})
			}else if(num == 5){
				//检查更新
				util.callHandler('checkAppVersion',{},res => {
					console.log(res)
				})
			}else if(num == 6){
				this.$router.push('/about')
			}else if(num == 7){
				this.iconShown2 = !this.iconShown2;
			}
		},
		init(){
			//获取默认颜色设置
			util.callHandler('getUpKLineColor',{},res => {
				// 0 红涨绿跌 1 绿涨红跌
				this.iconList.map(item => {
					item.color = res == item.id?'#0080FF':'';
				})
				this.defaultSet = {
					id:res,
					name:res==1?'绿涨红跌':'红涨绿跌'
				}
			})
			//获取版本号
			util.callHandler('getAppVersion',{},res => {
				this.needUpdate = res.needUpdate?true:false;
				// this.version = res.version;
			})
			//获取字体配置
			this.defaultSet2 = {
				id:1,
				name:'平台默认'
			}


			// let res = 0;
			// this.iconList.map(item => {
			// 	item.color = res == item.id?'#0080FF':'';
			// 	item.className = res == item.id?'on':'';
			// })
			// this.defaultSet = {
			// 	id:res,
			// 	name:res==1?'红跌绿涨':'红涨绿跌'
			// }
		},
		goBack(){
			util.navigateBack(-1,this)
		}
	},
	created() {
		util.waitSDKReady().then(token => {
			this.token = token;
			setTimeout(() => {
				this.init();
			},600)
		}).catch((e) => {
			Toast('获取token失败')
		})
		setTimeout(() => {
			util.registerHandler('refreshCommonRequestWhenGoBackView',res => {
				if(this.token) this.init();
				util.callHandler('setStatusBarStyle',{
					style:'dark'
				})
			})
			//退出登录的时候native调用H5方法清除token缓存
			util.registerHandler('loginOutDeleteToken',res => {
				window.token = '';
				this.token = '';
				localStorage.removeItem('token');
			})
			util.callHandler('setStatusBarStyle',{
				style:'dark'
			})
		},500)
    }
}